package helper.scxml.scxml2.t0.case2_traffic.zone.ts

import helper.base.debug.DebugHelper.DebuggerList
import helper.base.debug.DebugHelper.DebuggerList.Companion.makeDebuggerList
import helper.scxml.scxml2.t0.case2_traffic.zone.TrafficEnvHelper.TrafficEnv.Companion.makeTrafficEnv
import helper.scxml.strategy.sNodeUnit.T2SNodeUnitHelper.T2SNodeUnit

object T0Helper {
    class TaskUnit(
        val sNodeUnit: T2SNodeUnit,
    ) {
        companion object {
            fun getTaskUnit(
                sNodeUnit: T2SNodeUnit
            ): TaskUnit {
                return TaskUnit(
                    sNodeUnit
                )
            }
        }

        fun repeatRandomRun(
            repeatTimes: Int,
            debuggerList: DebuggerList = makeDebuggerList(),
        ) {
            val zoneEnv = makeTrafficEnv()
            val list = zoneEnv.repeatRandomRun(
                aSNU = sNodeUnit,
                repeatTimes = repeatTimes,
                debuggerList = debuggerList,
            )
            println("repeatTimes = $repeatTimes")
            arrayOf("t").forEach { keyStr ->
                list.map {
                    it.endData[keyStr]!!.toDouble()
                }.average().let {
                    println("average $keyStr = $it")
                }
            }
        }

        fun t1Cal(
            debuggerList: DebuggerList = makeDebuggerList(),
        ) {
            val zoneEnv = makeTrafficEnv()
            val result = zoneEnv.aT1Calculate(
                sNodeUnit,
                debuggerList,
            )
            println("result=${result}")
        }
    }
}